home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / hplip / hplip.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2007-04-04  |  4.6 KB  |  205 lines

  1. #! /bin/bash
  2. #
  3. # Startup/shutdown script for HPLIP 
  4. #
  5. # Note, this script file must start before cupsd.
  6. #
  7. # For chkconfig the HPLIP priority (ie: 50) must be less the cupsd 
  8. # priority (ie: 55).
  9. #
  10. # For LSB install_initd the cups script file should have "hplip" in the
  11. # Should-Start field.
  12. #   chkconfig: 2345 50 10
  13. #   description: Start/stop script for HP Linux Imaging and Printing (HPLIP).
  14. #
  15. # (c) 2004 Copyright Hewlett-Packard Development Company, LP
  16. #
  17. ### BEGIN INIT INFO
  18. # Provides: hplip
  19. # Required-Start:
  20. # Required-Stop:
  21. # Should-Start:
  22. # Should-Stop:
  23. # Default-Start: 3 5
  24. # Default-Stop: 
  25. # Description: Start/stop script for HP Linux Imaging and Printing (HPLIP)
  26. ### END INIT INFO
  27.  
  28. HPIODDIR=
  29. HPSSDDIR=
  30. RUNDIR=/var/run
  31.  
  32. if [ -f /etc/init.d/functions ] ; then
  33. . /etc/init.d/functions
  34. else
  35.  
  36. export PATH="/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
  37. export LC_ALL="POSIX"
  38. export LANG="POSIX"
  39. umask 022
  40.  
  41. daemon() {
  42.    $* >/dev/null 2>&1
  43.    if [ $? -eq 0 ]; then
  44.       echo -ne "                                           [  OK  ]\r"
  45.    else
  46.       echo -ne "                                           [FAILED]\r"
  47.    fi
  48. }
  49.  
  50. killproc() {
  51.    pid=`pidof -s $1`
  52.    pidfile=$RUNDIR/${1}.pid
  53.    if [ -z $pid ]; then
  54.       if [ -f $pidfile ]; then
  55.          read pid < $pidfile
  56.          kill $pid
  57.       fi      
  58.    else
  59.       kill $pid
  60.    fi
  61.    retval=$?
  62.    if [ -f $pidfile ]; then
  63.       rm $pidfile
  64.    fi      
  65.    if [ $retval -eq 0 ]; then
  66.       echo -ne "                                           [  OK  ]\r"
  67.    else
  68.       echo -ne "                                           [FAILED]\r"
  69.    fi
  70. }
  71.  
  72. fi 
  73.  
  74. mystatus() {
  75.    pid=`pidof -s $1`
  76.    if [ -z $pid ]; then
  77.       pidfile=$RUNDIR/${1}.pid
  78.       if [ -f $pidfile ]; then
  79.          read pid < $pidfile
  80.       fi      
  81.    fi
  82.  
  83.    if [ -n "$pid" ]; then
  84.       echo $"$1 (pid $pid) is running..."
  85.       return 0
  86.    fi
  87.  
  88.    echo $"$1 is stopped"
  89.    return 3
  90. }
  91.  
  92. RETVAL=0
  93.  
  94. start() {
  95.         echo -n $"Starting hpiod: "
  96.         cd $HPIODDIR
  97.         daemon ./hpiod
  98.         RETVAL=$?
  99.         echo
  100.         [ $RETVAL = 0 ] && [ -d /var/lock/subsys ] && touch /var/lock/subsys/hpiod
  101.         echo -n $"Starting hpssd: "
  102.         cd $HPSSDDIR
  103.         daemon ./hpssd.py
  104.         RETVAL=$?
  105.         echo
  106.         [ $RETVAL = 0 ] && [ -d /var/lock/subsys ] && touch /var/lock/subsys/hpssd.py
  107. #        killall -HUP cupsd
  108.         if [ -f /var/lock/subsys/hpiod -a -f /var/lock/subsys/hpssd.py ]; then
  109.            touch /var/lock/subsys/hplip
  110.     fi
  111.         return $RETVAL
  112. }
  113.  
  114. stop() {
  115.         echo -n $"Stopping hpiod: "
  116.         killproc hpiod
  117.         RETVAL=$?
  118.         echo
  119.         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/hpiod
  120.         echo -n $"Stopping hpssd: "
  121.         killproc hpssd
  122.         RETVAL=$?
  123.         echo
  124.         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/hpssd.py
  125.         for pidfile in $RUNDIR/*; do
  126.        case "$( basename $pidfile )" in 
  127.                hpguid-*.pid)
  128.                    read pid < $pidfile
  129.                    kill $pid
  130.                    rm $pidfile
  131.        esac
  132.         done
  133.         if [ ! -f /var/lock/subsys/hpiod -o ! -f /var/lock/subsys/hpssd.py ]; then
  134.             rm -f /var/lock/subsys/hplip
  135.         fi
  136.         return $RETVAL
  137. }       
  138.  
  139. restart() {
  140.         stop
  141.         start
  142. }       
  143.  
  144. debug() {
  145.         # Allow core dumps.
  146.         ulimit -c unlimited
  147.  
  148.         echo -n $"Starting hpiod: "
  149.         cd $HPIODDIR
  150.         ./hpiod >/dev/null 2>&1
  151.         RETVAL=$?
  152.         if [ $RETVAL -eq 0 ]; then
  153.            echo -ne "                                           [  OK  ]\r"
  154.         else
  155.            echo -ne "                                           [FAILED]\r"
  156.         fi
  157.         echo
  158.         [ $RETVAL = 0 ] && [ -d /var/lock/subsys ] && touch /var/lock/subsys/hpiod
  159.         echo -n $"Starting hpssd: "
  160.         cd $HPSSDDIR
  161.         ./hpssd.py >/dev/null 2>&1
  162.         RETVAL=$?
  163.         if [ $RETVAL -eq 0 ]; then
  164.            echo -ne "                                           [  OK  ]\r"
  165.         else
  166.            echo -ne "                                           [FAILED]\r"
  167.         fi
  168.         echo
  169.         [ $RETVAL = 0 ] && [ -d /var/lock/subsys ] && touch /var/lock/subsys/hpssd.py
  170.         if [ -f /var/lock/subsys/hpiod -a -f /var/lock/subsys/hpssd.py ]; then
  171.            touch /var/lock/subsys/hplip
  172.            return 0
  173.         else
  174.            return 1
  175.     fi
  176. }
  177.  
  178. case "$1" in
  179.   start)
  180.         start
  181.         ;;
  182.   stop)
  183.         stop
  184.         ;;
  185.   restart)
  186.         restart
  187.         ;;
  188.   status)
  189.         mystatus hpiod
  190.         mystatus hpssd
  191.         ;;
  192.   condrestart)
  193.         [ -f /var/lock/subsys/hpiod ] && [ -f /var/lock/subsys/hpssd.py ] && restart || :
  194.         ;;
  195.   debug)
  196.         debug
  197.         ;;
  198.   *)
  199.         echo $"Usage: $0 {start|stop|status|restart|condrestart}"
  200.         exit 1
  201. esac
  202.  
  203. exit $?
  204.